package com.blockmeta.bbs.immodule.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.utils.StatusBarUtils;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.businesslibrary.util.AccountHelper;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.R2;
import com.blockmeta.bbs.immodule.adapter.HongbaoGetDetailAdapter;
import com.blockmeta.bbs.immodule.bean.HongbaoDetail;
import com.blockmeta.bbs.immodule.bean.Params;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class HongbaoDetailActivity extends BaseActivity {

    @BindView(R2.id.fl_back)
    FrameLayout mFlBack;
    @BindView(R2.id.tv_title)
    TextView mTvTitle;
    @BindView(R2.id.rcv)
    RecyclerView mRcvFriends;
    @BindView(R2.id.title_container)
    View mSimpleTitle;

    @BindView(R2.id.tv_hongbao_result)
    TextView tvHongbaoResult;
    @BindView(R2.id.tv_hongbao_unit)
    TextView tvHongbaoUnit;
    @BindView(R2.id.tv_my_coin)
    TextView tvMyCoin;
    @BindView(R2.id.tv_hongbao_get_num)
    TextView tvHongbaoGetNum;
    @BindView(R2.id.tv_hongbao_nothing)
    TextView tvHongbaoNothing;

    private long mChatGroupId;
    public HongbaoGetDetailAdapter mHongbaoGetDetailAdapter;
    private HongbaoDetail mHongbaoDetail;


    @Override
    protected boolean showTitle() {
        return false;
    }

    @Override
    public void setStatusBarColor() {
        StatusBarUtils.setWindowStatusBarColor(this, R.color.status_trans);
        StatusBarUtils.setWindowFullScreen(this);
    }

    @Override
    public View setView() {
        return getLayoutInflater().inflate(R.layout.activity_hongbao_detail, null);
    }

    @Override
    protected void initialize() {
        super.initialize();

        mHongbaoDetail = getIntent().getParcelableExtra(Params.HONGBAODETAIL);
        mChatGroupId = getIntent().getLongExtra(Params.CIRCLE_ID, 0);
        if (mHongbaoDetail == null || mHongbaoDetail.getCandyKidsList() == null || mHongbaoDetail.getCandyKidsList().size() == 0) {
            finish();
            return;
        }

        mRcvFriends.setLayoutManager(new LinearLayoutManager(this));
        mHongbaoGetDetailAdapter = new HongbaoGetDetailAdapter(R.layout.item_hongbao_get_person, mHongbaoDetail.getCandyKidsList(), mChatGroupId);
        mHongbaoGetDetailAdapter.bindToRecyclerView(mRcvFriends);


        List<HongbaoDetail.CandyKidsListBean> candyKidsList;
        candyKidsList = mHongbaoDetail.getCandyKidsList();
        int myCoin = 0, hadQiangCount = 0;
        if (candyKidsList != null) {
            int size = candyKidsList.size();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    HongbaoDetail.CandyKidsListBean bean = candyKidsList.get(i);
                    if(bean.getCandyNum() > 0){
                        hadQiangCount++;
                    }
                    if (bean.getUserId() == AccountHelper.getUidInt()) {
                        myCoin = bean.getCandyNum();
                    }
                }
            }
        }
        if(myCoin == 0){
            tvHongbaoResult.setVisibility(View.GONE);
            tvHongbaoUnit.setVisibility(View.GONE);
            tvHongbaoNothing.setVisibility(View.VISIBLE);
        }else {
            tvHongbaoResult.setText(myCoin + "");
            tvHongbaoGetNum.setText("领取 " + hadQiangCount + "/" + mHongbaoDetail.getUserNum());
        }

    }


    @OnClick({R2.id.fl_back, R2.id.tv_my_coin})
    public void onViewClicked(View view) {
        int i = view.getId();
        if (i == R.id.fl_back) {
            finish();

        } else if(i == R.id.tv_my_coin) {
            RouterHelper.startActivity(RouterPath.TASK_CENTER_ACTIVITY);
        } else {

        }

    }


}
